{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "4a5b88da",
   "metadata": {},
   "source": [
    "# week02 python笔记"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9a5d2278",
   "metadata": {},
   "source": [
    "## 1.从基数中选择对应的时间节点"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "be90d3cd",
   "metadata": {},
   "source": [
    "## 1.1用datetime模板显示日期"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "79536c81",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "datetime.date(2021, 9, 28)"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import datetime\n",
    "datetime.date.today()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "77c56b22",
   "metadata": {},
   "source": [
    "## 1.2从奇数中选择对应的时间节点"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "261446e2",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "This minute seems a little odd.\n"
     ]
    }
   ],
   "source": [
    "from datetime import datetime\n",
    "odds = [1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,43,45,47,49,51,53,55,57,59]\n",
    "right_this_second = datetime.today().second\n",
    "if right_this_second in odds:\n",
    "    print(\"This minute seems a little odd.\")\n",
    "else:\n",
    "    print(\"Not an odd minute.\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "f69e678a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "7"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "right_this_second"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "35d5e829",
   "metadata": {},
   "source": [
    "## 2.认识变量（数字，字符串，对象）"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "92d50559",
   "metadata": {},
   "source": [
    "## 2.1numbers"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "b4ab02a2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "9"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    ">>> 4 + 5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "fa6cf0f5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "25.0"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    ">>> (80-5*6)/2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "f89ca83c",
   "metadata": {},
   "outputs": [],
   "source": [
    "age_Wendy = 27"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "49e4e684",
   "metadata": {},
   "outputs": [],
   "source": [
    "age_Irene = 27 + 3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "fbf9ae2e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"doesn't\""
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"doesn't\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "4fcf8e52",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"doesnt't\""
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'doesnt\\'t'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "30da439d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'\"Yes,\" they said.'"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'\"Yes,\" they said.'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "30a8bd6e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'\"don\\'t,\" they said.'"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'\"don\\'t,\" they said.'"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9550d777",
   "metadata": {},
   "source": [
    "## 2.3对象"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "758517ff",
   "metadata": {},
   "source": [
    "## 在Python中，一切都是对象"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "771e09dd",
   "metadata": {},
   "source": [
    "## 3.if and else"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "ee5c9898",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Not an odd minute.\n"
     ]
    }
   ],
   "source": [
    "from datetime import datetime\n",
    "odds = [1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,43,45,47,49,51,53,55,57,59]\n",
    "right_this_second = datetime.today().second\n",
    "if right_this_second in odds: ###此“if”语句结果为“true\"或“false”\n",
    "    print(\"This minute seems a little odd.\")###这是一个代码块（是缩进的）\n",
    "else:###“else”语句，指示当对应的“if”语句返回一个false值时要执行的代码块\n",
    "    print(\"Not an odd minute.\")###这也是一个代码块（是缩进的）"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "743fe512",
   "metadata": {},
   "source": [
    "## 4.for+range"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8e10ea40",
   "metadata": {},
   "source": [
    "## for的三种典型用法"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a7ab1127",
   "metadata": {},
   "source": [
    "## 例子1 已知循环次数情况下使用for"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "d0fe7438",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "2\n",
      "3\n",
      "4\n",
      "5\n",
      "6\n"
     ]
    }
   ],
   "source": [
    "for i in [1,2,3,4,5,6]:### 用“i”作为循环迭代变量\n",
    "    print(i)### 这是一个代码组 需要按两次回车才能执行"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "02619e7a",
   "metadata": {},
   "source": [
    "## 例子2 序列是一个有序的对象集合"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "9e72ea90",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "I\n",
      "'\n",
      "m\n",
      " \n",
      "W\n",
      "e\n",
      "n\n",
      "d\n",
      "y\n",
      ",\n",
      "f\n",
      "r\n",
      "o\n",
      "m\n",
      " \n",
      "R\n",
      "e\n",
      "d\n",
      " \n",
      "V\n",
      "e\n",
      "l\n",
      "v\n",
      "e\n",
      "t\n"
     ]
    }
   ],
   "source": [
    "for ch in \"I'm Wendy,from Red Velvet\":\n",
    "    print(ch)###字符串迭代处理 一次处理一个字符"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9e5a63a7",
   "metadata": {},
   "source": [
    "## 例子3 迭代指定的次数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "9b8d6fbc",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "I am Wendy,from Red Velvet\n",
      "I am Wendy,from Red Velvet\n",
      "I am Wendy,from Red Velvet\n",
      "I am Wendy,from Red Velvet\n",
      "I am Wendy,from Red Velvet\n",
      "I am Wendy,from Red Velvet\n",
      "I am Wendy,from Red Velvet\n"
     ]
    }
   ],
   "source": [
    "for num in range(7):###请求包含七个数的范围 因此迭代七次\n",
    "    print('I am Wendy,from Red Velvet')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "541f37f7",
   "metadata": {},
   "source": [
    "## range试验"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "4e252efe",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "range(0, 7)"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "range(7) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "45e943a2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[0, 1, 2, 3, 4, 5, 6]"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(range(7))###将“range”的输出输入到“list”中会生成一个列表"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "e9dca765",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[4, 5, 6]"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(range(4,7))###可以调整“range”的START和STOP值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "fedbe8c4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[2, 6]"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(range(2,8,4))###可以调整STEP值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "1def73bd",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[15, 10]"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(range(15,5,-5))###通过设置STEP为负值来调整范围方向"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "88565e3a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[]"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(range(25,5,10))###如果START值大于STOP值，而STEP为正值，将得不到什么结果"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2693ad71",
   "metadata": {},
   "source": [
    "## 自制歌谣代码"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "5f85c770",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "8 Queendom how you like that \n",
      "8 Queendom  play with fire.\n",
      "it is alright.\n",
      "Pass it around.\n",
      "7 Queendom you got me feeling like a s'psycho.\n",
      "\n",
      "4 Queendom how you like that \n",
      "4 Queendom  play with fire.\n",
      "it is alright.\n",
      "Pass it around.\n",
      "3 Queendom you got me feeling like a s'psycho.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "word = \"Queendom\"\n",
    "for beer_num in range(8,0,-4):\n",
    "    print(beer_num,word,\"how you like that \")\n",
    "    print(beer_num,word,\" play with fire.\")\n",
    "    print(\"it is alright.\")\n",
    "    print(\"Pass it around.\")\n",
    "    if beer_num == 1:\n",
    "        print(\"you got me feeling like a s'psycho.\")\n",
    "    else:\n",
    "        new_num = beer_num - 1\n",
    "        if new_num == 1:\n",
    "            word = \"psycho\"\n",
    "        print(new_num,word,\"you got me feeling like a s'psycho.\")\n",
    "        print()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f7bfdfea",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
